#!/bin/bash

function all()
{
    tmp_build_output_path=$BUILD_OUTPUT_PATH
    if [ -z "${BUILD_OUTPUT_PATH}" ]; then
        export BUILD_OUTPUT_PATH="$(pwd)"
    else
        export BUILD_OUTPUT_PATH=$tmp_build_output_path/daemon/
    fi
    echo "build libclog"
    make -j${N} || {
        echo "make failed"
        exit 1
    }
    echo "build libclog done"

    export BUILD_OUTPUT_PATH=$tmp_build_output_path
}

function clean()
{
    echo "clean files"
    make clean -j${N} || {
        echo "make failed"
        exit 1
    }
}

function buildopt()
{
    buildopt=$1
    echo "buildopt: $buildopt"

    if [ "$buildopt" == "all" ]; then
        echo "build all"
        all
    elif [ "$buildopt" == "clean" ]; then
        echo "build clean"
        clean
    else
        echo "Usage: $0 [all|clean]"
        exit 1
    fi
}

buildopt $1